var PreOrderForm = function () {
  var template = /*html*/ `
    <div class="pre-order-form" v-loading.fullscreen.lock="loading">
      <div>
        <el-form :model="updateOrder" label-width="195px">
          <el-form-item label="订单编号">
            <span>{{updateOrder.companyOrderId}}</span>
          </el-form-item>
          <el-form-item label="客户型号">
            <span>{{updateOrder.articleNo}}</span>
          </el-form-item>
          <el-form-item label="供应商">
            <span>{{updateOrder.factoryNo}}</span>
          </el-form-item>
          <el-form-item label="采购员">
            <span>{{updateOrder.providerName}}</span>
          </el-form-item>
          <el-form-item label="物料名称">
            <span>{{updateOrder.materialName}}</span>
          </el-form-item>
          <el-form-item label="物料类型">
            <span>{{updateOrder.materialType}}</span>
          </el-form-item>
          <el-form-item label="编号">
            <el-input v-model="updateOrder.color" @change="colorChange"></el-input>
          </el-form-item>
          <el-form-item label="描述">
            <el-input v-model="updateOrder.colorDescription"></el-input>
          </el-form-item>
          <el-form-item label="采购数量">
            <span>{{updateOrder.purchaseCount}}</span>
          </el-form-item>
          <el-form-item label="规格型号">
            <span>{{updateOrder.model}}</span>
          </el-form-item>
          <el-form-item label="材质">
            <span>{{updateOrder.material}}</span>
          </el-form-item>
          <el-form-item label="单位">
            <span>{{updateOrder.unit}}</span>
          </el-form-item>
          <el-form-item label="含税单价">
            <span>{{updateOrder.price}}</span>
          </el-form-item>
          <el-form-item label="金额">
            <span>{{updateOrder.totalMoney}}</span>
          </el-form-item>
          <el-form-item label="税率">
            <span>{{updateOrder.tax}}</span>
          </el-form-item>
          <el-form-item label="仓库">
            <span>{{updateOrder.defaultWarehouse}}</span>
          </el-form-item>
        </el-form>
      </div>
      <div class="form-btns">
        <el-button type="primary" @click="updateData" :loading="btnLoading">修改</el-button>
      </div>
    </div>
  `;

  return {
    props: {
      order: {
        type: Object,
        required: true
      }
    },
    data: function () {
      return {
        loading: false,
        canUpdate: true,
        btnLoading:false,
        updateOrder: _.cloneDeep(this.order)
      };
    },
    methods: {
      colorChange: function () {
        var updateOrder = this.updateOrder;
        var postData = updateOrder.getSearchObject();
        var self = this;
        this.btnLoading = true;
        ajaxRequest('basicData/getCompanyMaterialListByDetail', postData).then(function (data) {
          self.canUpdate = SysUtil.isEmpty(data);
          self.btnLoading = false;
        }).catch(function(){
          self.canUpdate = false;
          self.btnLoading = false;
        });
      },
      updateData: function () {
        var canUpdate = this.canUpdate;
        if (!canUpdate){
          this.$alert('该物料已存在，请再次确认','信息');
          return;
        }
        var updateOrder = this.updateOrder;
        var postData = updateOrder.getObject();
        this.loading = true;
        var self = this;
        ajaxRequest('advancePurchase/updateAdvancePurchaseByMainId',postData).then(function(){
          self.loading = false;
          self.$alert('预购单修改成功','信息',{
            callback:function(){
              self.$emit('update-success');
            }
          })
        }).catch(function(){
          self.loading = false;
        });
      }
    },
    template: template
  };
}();